<template lang="jade">
div
  h-data-adder(url='audio/add')
    m-title(icon="add",name='添加音频')
    table.single
      mf-row(name='标题：'): input(type='text',v-model='data.name')
      mf-row(name='简述：'): input(type='text',v-model='data.intro')
      mf-row(name='上传音频：', id="form_area")
        form(enctype="multipart/form-data", id="form")
          input(type='file', name="file", id="file")
      mf-row(name='音频链接：'): input(type='text', readonly="readonly" v-model='data.url')
      mf-row(name='音频图片：'): mf-upload(uploadid='img', amount='1',project='xiongan',category='logo',@upload_data='text',:data='data.img')
      mf-row(name='创建时间：'): input(type='datetime-local',v-model='data.time')
      mf-row(name='')
        button(id='button') 确认添加
</template>

<script>

export default {
	data () {
		return {
			data:{
        name:'',
        intro:'',
        img:[],
        time:'',
        url:"",
      },
      loader:{

      }
		}
	},
	mounted () {
      $("#form_area").find("em").remove();
      $("#file").change(()=>{
        var formData = new FormData($("#form"));
        formData.append("file", document.getElementById("file").files[0]);  
        if($("#file").val() == ""){
          alert("没有上传任何文件");
          return;
        }
        $.ajax({
            url: 'http://hxq.test.sgboke.com/uploadaudio.php',
            type:"post",
            data:formData,
            processData:false,
            contentType:false,
            success:(res) => {
               this.data.url = res;
            },
            error:(err)=>{
              console.log(err);
            },
        })
      })
	},
	methods: {
    text(data){
			this.data.img = data
    },

    addBefore(){
      for(var key in this.data){
        if(this.data[key] == ''){
          this.$msg.error("所有均不能为空")
          return;
        }
      }
      return 1;
    },

    addAfter (res) {
			this.$msg.success(res.manager)
      setTimeout('window.location.reload()',1500)
		},
	}
}
</script>

<style lang="less">
@import "../../../plugin/style/mixin.less";

</style>